//
// Created by guanyicheng on 2022/2/10.
//
#include "../../common.h"

class Solution {
public:
    int minSubArrayLen(int target, vector<int> &nums) {
        int i = 0, j = 0, sum = 0, l = nums.size() + 1;
        while (true) {
            if (sum < target) {
                if (j == nums.size()) {
                    break;
                }
                sum += nums[j++];
            } else {
                l = min(l, j - i);
                sum -= nums[i++];
            }
        }
        return l == nums.size() + 1 ? 0 : l;
    }
};


int main() {

    auto v = vector<int>{2};
    cout << Solution().minSubArrayLen(7, v) << endl;
}